Skip to content

[asm] Handle PackOp inputs in regalloc liveness and linear scan#1144

Open
Hardcode84 wants to merge 2 commits intoiree-org:mainfrom
Hardcode84:waveasm-pack-regalloc
Open

[asm] Handle PackOp inputs in regalloc liveness and linear scan#1144
Hardcode84 wants to merge 2 commits intoiree-org:mainfrom
Hardcode84:waveasm-pack-regalloc

Conversation

@Hardcode84
Copy link
Contributor

@Hardcode84 Hardcode84 commented Mar 18, 2026

PackOp is a register allocation directive: its N inputs must form a contiguous register block matching the pack result. Previously, pack inputs got independent allocations to arbitrary registers while the result got a correct contiguous allocation, leaving downstream consumers reading uninitialized physical registers.

Fix by treating pack inputs as sub-registers of the pack result:

  • Liveness: extend the pack result's live range backwards to cover input defs, then remove inputs from allocation worklists.
  • LinearScanPass: post-pass assigns input[i].physReg = result + i, mirroring the existing ExtractOp post-pass.

This is prerequisite for properly handling SRD construction instead of using raw asm ops.

@Hardcode84 Hardcode84 changed the title Handle PackOp inputs in regalloc liveness and linear scan [asm] Handle PackOp inputs in regalloc liveness and linear scan Mar 18, 2026
@Hardcode84 Hardcode84 force-pushed the waveasm-pack-regalloc branch from 8582ac3 to dbe05c6 Compare March 20, 2026 19:00
"pack result must have a live range");

for (Value input : packOp.getElements()) {
// Extend the pack result's range start to cover this input's def.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it guaranteed that pack inputs have no uses other than through the pack result? If a pack input value is also used independently after the pack op, then erasing its live range and only extending the pack result's start could miss extending the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, we need to extend pack op live range to the entire input lifetime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Hardcode84 and others added 2 commits March 23, 2026 21:39
PackOp is a register allocation directive: its N inputs must form a
contiguous register block matching the pack result. Previously, pack
inputs got independent allocations to arbitrary registers while the
result got a correct contiguous allocation, leaving downstream
consumers reading uninitialized physical registers.

Fix by treating pack inputs as sub-registers of the pack result:
- Liveness: extend the pack result's live range backwards to cover
  input defs, then remove inputs from allocation worklists.
- LinearScanPass: post-pass assigns input[i].physReg = result + i,
  mirroring the existing ExtractOp post-pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Previously only the start of pack inputs' live ranges was merged into
the pack result. If a pack input had independent uses after the pack op,
the allocator could reuse its physical register prematurely.

Fix by extending the pack result's end to the max of all input ends.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
@Hardcode84 Hardcode84 force-pushed the waveasm-pack-regalloc branch from dbe05c6 to 9f1be23 Compare March 23, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants